package com.meida.module.bus.provider.controller;

import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.springmvc.base.BaseController;
import com.meida.common.utils.StringUtils;
import com.meida.module.bus.client.entity.BusDept;
import com.meida.module.bus.provider.service.BusDeptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 部门控制器
 *
 * @author flyme
 * @date 2020-12-16
 */
@RestController
@RequestMapping("/bus/dept/")
public class BusDeptController extends BaseController<BusDeptService, BusDept>  {

    @ApiOperation(value = "部门-分页列表", notes = "部门分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "部门-列表", notes = "部门列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "部门-添加", notes = "添加部门")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "部门-更新", notes = "更新部门")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "部门-删除", notes = "删除部门")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "部门-详情", notes = "部门详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "用户分配部门", notes = "用户分配部门")
    @PostMapping("/setDept")
    public ResultBody addUserDepts(
        @RequestParam(value = "userId") Long userId,
        @RequestParam(value = "deptIds", required = false) String deptIds
    ) {
        bizService.saveUserDepts(userId, StringUtils.isNotBlank(deptIds) ? deptIds.split(",") : new String[]{});
        return ResultBody.msg("设置成功");
    }

    @ApiOperation(value = "部门项目", notes = "部门项目")
    @GetMapping(value = "getAllDeptProject")
    public ResultBody getAllDeptProject() {
        return bizService.getAllDeptProject();
    }

}
